//
//  YuYueFooterView.m
//  FD
//
//  Created by xiaofang wang on 2018/11/8.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//  120 - 20(现在,预约成功之后前往餐厅) - 20 

#import "YuYueFooterView.h"
#import "NSAttributedString+YYText.h"

@interface YuYueFooterView()
/**1.用餐时间*/
@property (nonatomic, strong) UILabel *titleLb;
/**👆的*/
@property (nonatomic, strong) UIView *uperView;

/**2019-2-25 要都能点*/
@property (nonatomic, strong) UIView *downView;

//12-5不要了
///**2.现在用餐按钮*/
//@property (nonatomic, strong) UIButton *btn1;
///**2-1 tipsLB*/
//@property (nonatomic, strong) UILabel *xianZaiYongCanLb;


/**3-1预约用餐btn*/
@property (nonatomic, strong) UIButton *btn2;
/**3-2预约用餐按钮*/
@property (nonatomic, strong) UILabel *yuyueLb;

@end

@implementation YuYueFooterView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
        self.backgroundColor = kMainLightGrayColor;
    }
    return self;
}
- (void)setupView
{
    [self addSubview:self.uperView];
    [self.uperView addSubview:self.titleLb];
    

    [self addSubview:self.downView];
    
//    [self.downView addSubview:self.btn1];
//    [self.downView addSubview:self.xianZaiYongCanLb];
    
    [self.downView addSubview:self.btn2];
    [self.downView addSubview:self.yuyueLb];
}


#pragma mark - layout
- (void)layoutSubviews {
    [super layoutSubviews];
    
    
    [self.uperView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self);
        make.height.mas_equalTo(40);
    }];
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.size.mas_equalTo(CGSizeMake(100, 20));
        make.left.equalTo(self.mas_left).offset(15);
        make.width.mas_greaterThanOrEqualTo(100); //2019-2-22防止国际化显示不全
        make.height.mas_equalTo(20); //
        make.centerY.equalTo(self.uperView.mas_centerY);
    }];
    //====================
    
    
    [self.downView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.uperView.mas_bottom).offset(1);
        make.left.right.equalTo(self);
        make.bottom.equalTo(self.mas_bottom);
    }];
    
    
    
//    [self.btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.downView.mas_left).offset(15);
//        make.size.mas_equalTo(CGSizeMake(20, 20));
//        make.top.equalTo(self.downView.mas_top).offset(10);
//    }];
//    [self.xianZaiYongCanLb mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.btn1.mas_right).offset(5);
//        make.height.mas_offset(20);
//        make.top.equalTo(self.btn1.mas_top);
//        make.right.equalTo(self.downView.mas_right).offset(-10);
//    }];
//
//    [self.btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.downView).offset(15);
//        make.top.equalTo(self.btn1.mas_bottom).offset(10);
//        make.size.mas_equalTo(CGSizeMake(20, 20));
//    }];
//    [self.yuyueLb mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.btn2.mas_top);
//        make.left.equalTo(self.btn2.mas_right).offset(5);
//        make.size.mas_equalTo(CGSizeMake(280, 20));
//    }];
    
        [self.btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.downView).offset(15);
            make.top.equalTo(self.downView.mas_top).offset(10);
            make.size.mas_equalTo(CGSizeMake(20, 20));
        }];
        [self.yuyueLb mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(self.btn2.mas_top);
//            make.left.equalTo(self.btn2.mas_right).offset(5);
//            make.size.mas_equalTo(CGSizeMake(280, 20));
            
            //2-22防止国际化显示不全
            make.left.equalTo(self.btn2.mas_right).offset(5);
            make.top.right.bottom.equalTo(self.downView);
        }];
}

#pragma mark - getter
- (UILabel *)titleLb {
    if (!_titleLb) {
        _titleLb = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
        
        //国际化
        NSString *yongcanTimeStr = NSLocalizedString(Home_eatTime, @"用餐时间");
        _titleLb.text = yongcanTimeStr;
    }
    return _titleLb;
}

- (UIView *)uperView {
    if (!_uperView) {
        _uperView = [UIView new];
        _uperView.backgroundColor = [UIColor whiteColor];
    }
    return _uperView;
}


- (UIView *)downView {
    if (!_downView) {
        _downView = [UIView new];
        _downView.backgroundColor = [UIColor whiteColor];
        
        //添加手势
        UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] init];
        [tapGes addTarget:self action:@selector(clickTapGestureAction)];
        [_downView addGestureRecognizer:tapGes];
    }
    return _downView;
}

//- (UILabel *)xianZaiYongCanLb {
//    if (!_xianZaiYongCanLb) {
//        _xianZaiYongCanLb = [UILabel new];
//
//        //国际化
//        NSString *str = NSLocalizedString(Home_nowEat, @"现在，预约成功后前往餐厅用餐");
//        _xianZaiYongCanLb.text = str;
//    }
//    return _xianZaiYongCanLb;
//}
- (UILabel *)yuyueLb {
    if (!_yuyueLb) {
        _yuyueLb = [UILabel new];
        
        //国际化
//        NSString *yuyueStr = NSLocalizedString(Home_yuYu, @"预约");
//        NSString *yongcanStr = NSLocalizedString(Home_yongCan, @"用餐");
//        _yuyueLb.text = [NSString stringWithFormat:@"%@%@",yuyueStr,yongcanStr];
        
        //2019-2-22
        _yuyueLb.text = NSLocalizedString(Home_YuYueYongCan, @"预约用餐");
        _yuyueLb.numberOfLines = 0;
        //2019-2-25打卡用户交互
        _yuyueLb.userInteractionEnabled = YES;
    }
    return _yuyueLb;
}


//- (UIButton *)btn1 {
//    if (!_btn1) {
//        _btn1 = [self createBtnWithTarget:self action:@selector(clickBtn1Action:)];
//    }
//    return _btn1;
//}


- (UIButton *)btn2 {
    if (!_btn2) {
        _btn2 = [self createBtnWithTarget:self];
    }
    return _btn2;
}



#pragma mark - private method
- (UIButton *)createBtnWithTarget:(id)target{
    UIButton *btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [btn setImage:[UIImage imageNamed:@"unselected"] forState:(UIControlStateNormal)];
    [btn setImage:[UIImage imageNamed:@"selected"] forState:    (UIControlStateSelected)];
    return btn;
}

//- (UIButton *)createBtnWithTarget:(id)target action:(SEL)action {
//    UIButton *btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
//    [btn setImage:[UIImage imageNamed:@"unselected"] forState:(UIControlStateNormal)];
//    [btn setImage:[UIImage imageNamed:@"selected"] forState:    (UIControlStateSelected)];
//
//    [btn addTarget:target action:action forControlEvents:(UIControlEventTouchUpInside)];
//
//    return btn;
//}


#pragma mark - 点击事件
//- (void)clickBtn1Action:(UIButton *)btn
//{
//    btn.selected = YES;
//    self.btn2.selected = NO;
//}

//- (void)clickBtn2Action:(UIButton *)btn {
//    btn.selected = YES;
//    if (self.footerViewClickYuYueTimeBlock) {
//        self.footerViewClickYuYueTimeBlock();
//    }
//}

- (void)clickTapGestureAction {
    self.btn2.selected = YES;
    if (self.footerViewClickYuYueTimeBlock) {
        self.footerViewClickYuYueTimeBlock();
    }
}


- (void)updateYuYueTimestr:(NSString *)timestr {
    
    //国际化
    NSString *yuyueStr = NSLocalizedString(Home_yuYu, @"预约");
    
//2019-2-23不要了
//    NSString *yongcanStr = NSLocalizedString(Home_yongCan, @"用餐");
//    NSString *str = [NSString stringWithFormat:@"%@ %@ %@",yuyueStr,timestr,yongcanStr];
        NSString *str = [NSString stringWithFormat:@"%@ %@",yuyueStr,timestr];
    
    NSRange range = [str rangeOfString:timestr];
    UIColor *blackColor = [UIColor blackColor];
    UIColor *redColor = [UIColor redColor];
    UIColor *clearColor = [UIColor clearColor];

    //属性
    NSDictionary *attDic = @{NSForegroundColorAttributeName:blackColor,NSFontAttributeName:[UIFont systemFontOfSize:16.0]};
    //富文本
    NSMutableAttributedString *attM = [[NSMutableAttributedString alloc] initWithString:str attributes:attDic];
    [attM yy_setTextHighlightRange:range color:redColor backgroundColor:clearColor userInfo:nil];

    //设置富文本
    self.yuyueLb.attributedText = attM;
}

@end
